package host

import (
	"database/sql"
	"github.com/gogf/gf/database/gdb"
)

// Entity is the golang structure for table host.
type Entity struct {
    Id             int  `orm:"id,primary"      json:"id"`                // 主键                                              
    Uuid           string `orm:"uuid"            json:"uuid"`            // UUID                                              
    Hostname       string `orm:"hostname"        json:"hostname"`        // 主机名                                            
    Ipaddr         string `orm:"ipaddr"          json:"ipaddr"`          // ip地址                                            
    SigninUser     string `orm:"signin_user"     json:"signinUser"`      // ssh登录用户                                       
    SigninPassword string `orm:"signin_password" json:"signinPassword"`  // ssh密码
    SigninPort     string `orm:"signin_port"     json:"signinPort"`      // ssh密码                                    
    Salt           string `orm:"salt"            json:"salt"`            // 密码盐                                            
    UserId         int    `orm:"user_id"         json:"userId"`          // 所属用户/11111/dict                               
    Area           int    `orm:"area"            json:"area"`            // 类型//select/1,办公区,2,测试区,3,运维区,4,生产区  
    Status         int    `orm:"status"          json:"status"`          // 状态//select/1,启用,2,关机                        
    Remark         string `orm:"remark"          json:"remark"`          // 说明                                              
    Theme          string `orm:"theme"           json:"theme"`           // 主题                                              
    UpdateTime     string `orm:"update_time"     json:"updateTime"`      // 更新时间                                          
    UpdateId       int  `orm:"update_id"       json:"updateId"`          // 更新人                                            
    CreateTime     string `orm:"create_time"     json:"createTime"`      // 创建时间                                          
    CreateId       int  `orm:"create_id"       json:"createId"`          // 创建者     

    Owner string `json:"owner" gconv:"owner,omitempty"` // 父节点名称
	UpdateName string `json:"updateName,omitempty" gconv:"updateName,omitempty"`
	CreateName string `json:"createName,omitempty" gconv:"createName,omitempty"`                                 
}

// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (r *Entity) OmitEmpty() *arModel {
	return Model.Data(r).OmitEmpty()
}

// Inserts does "INSERT...INTO..." statement for inserting current object into table.
func (r *Entity) Insert() (result sql.Result, err error) {
	return Model.Data(r).Insert()
}

// Replace does "REPLACE...INTO..." statement for inserting current object into table.
// If there's already another same record in the table (it checks using primary key or unique index),
// it deletes it and insert this one.
func (r *Entity) Replace() (result sql.Result, err error) {
	return Model.Data(r).Replace()
}

// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Entity) Save() (result sql.Result, err error) {
	return Model.Data(r).Save()
}

// Update does "UPDATE...WHERE..." statement for updating current object from table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Entity) Update() (result sql.Result, err error) {
	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
}

// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
func (r *Entity) Delete() (result sql.Result, err error) {
	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
}